import {
  Module,
  NestModule,
  MiddlewareConsumer,
  forwardRef,
} from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { mysqlConfig } from './config/mysql.config';

import { GetToken } from './common/middleware/getToken.middleware';

import { ResInterceptor } from './common/Interceptors/res.interceptor';
import { WsModule } from './ws/ws';
import { WxModule } from './app/wx/wx.module';
import { orderModule } from './app/order/order.module';
import { AdminModule } from './app/admin/admin.module';
import { UserModule } from './app/user/user.module';
import { UtilsModule } from './util/utils.module';
import { WxApiModule } from './common/wxapi/wxapi.module';
import { IndexModule } from './app/index/index.module';
import { GoodsModule } from './app/goods/goods.module';
import { DeviceModule } from './app/device/device.module';
import { SysModule } from './app/sys/sys.module';
import { CallerModule } from './app/caller/caller.module';
const config: object =
  process.env.NODE_ENV == 'production'
    ? mysqlConfig.production
    : mysqlConfig.development;
@Module({
  imports: [
    TypeOrmModule.forRoot(config),
    WsModule,
    DeviceModule,
    IndexModule,
    orderModule,
    AdminModule,
    UserModule,
    SysModule,
    GoodsModule,
    CallerModule,
    WxModule,
    WxApiModule,
    UtilsModule,
  ],
  controllers: [],
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: ResInterceptor,
    },
  ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(GetToken).forRoutes('');
  }
}
